%h2
  = _("Edit Media")
  = image_tag "indicator_arrows.gif",:id=>"busy_edit",:style=>"display:none;"
- form_tag :action => 'update', :id => @media do
  %p
    = _("Title")
    = ":"
    = text_field 'media', 'title',:value=>HTMLEntities.decode_entities(@media.title)
  %p
    = _("Text")
    = "<br/>"
    = find_and_preserve(textile_editor 'media', 'text',:cols=>80,:rows=>20,:value=>HTMLEntities.decode_entities(@media.text))
  #preview  
  = link_to_remote "Preview", :url => { :action => "preview", :controller => "media" },:update => "preview",:with => "'text=' + encodeURIComponent($('media_text').value)+'&title='+encodeURIComponent($('media_title').value)",:loading => "Element.show('busy_edit')",:complete => "Element.hide('busy_edit')" 
  = "<br>"
  %p
    = _("Category")
    %select{:id=>"media_category_id", :name=>"media[category_id]"}
      - @categories.each do |thecategory|
        - if thecategory.id==@media.category_id
          %option{:value=>thecategory.id, :selected=>true}
            = thecategory.name
        - else
          %option{:value=>thecategory.id}
            = thecategory.name
  %p
    = _("Tags")
    = ":"
    #tags_field
      = text_area('form', 'tags',:cols=>100,:rows=>5,:value=>@media.tag_list)+"<br />"
    = _("Existing tags")+":<br />"
    = Tag.find(:all,:order=>"name ASC").collect {|t| link_to_remote(t.name,:update=>"tags_field",:loading => "Element.show('busy_edit')",:complete => "Element.hide('busy_edit')" ,:url=>{:action=>"update_tags"},:with=>"'tag=#{t.name}'+'&list='+encodeURIComponent($('form_tags').value)")}.join(" ")+"<br />"
  %p
    = _("Published")
    = ":"
    = check_box 'media', 'published',:onclick=>"Element.toggle('publicationdate')"
  - if @media.published==1
    %p{:id=>"publicationdate",:style=>'display:block;'}
      = _("Publication date")
      = ":"
      = calendar_date_select_tag "media_publicationdate", @media.publicationdate, :time => true,:name=>"media[publicationdate]"
  - else
    %p{:id=>"publicationdate",:style=>'display:none;'}
      = _("Publication date")
      = ":"
      = calendar_date_select_tag "media_publicationdate", @media.publicationdate, :time => true,:name=>"media[publicationdate]"
  %p
    %label{:for=>"media_expires"}
      = _("Expires")
    = ":"
    = check_box 'media', 'expires',:onclick=>"Element.toggle('expirationdate')"
  - if @media.expires==1 
    %p{:id=>"expirationdate",:style=>'display:block;'}
      = _("Expiration date")
      = ":"
      = calendar_date_select_tag "media_expirationdate", @media.expirationdate, :time => true,:name=>"media[expirationdate]"
  - else
    %p{:id=>"expirationdate", :style=>'display:none;'}
      = _("Expiration date")
      = ":"
      = calendar_date_select_tag "media_expirationdate", @media.expirationdate, :time => true,:name=>"media[expirationdate]"
  = submit_tag _('Save')
  = textile_editor_initialize
= "<br />"
= link_to _('Show'), :action => 'show', :id => @media
= "|"
- if @media.type_id==1
  = link_to (_('Back'), :action => 'list')
- else
  = link_to (_('Back'), :action => 'listpages' )
= "<br />"
